﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;
using FilStartUps.Helper;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_GetFeaturedPost : System.Web.UI.UserControl
    {
        private void GetFeatured()
        {
            try
            {
                var featured = FilStartUpsAPI.GetFeaturedPost();

                for (int i = 1; i <= featured.Count(); i++)
                {
                    if (i == 1)
                    {
                       
                        lb1.Visible = true;
                        lt_1.Visible = true;
                        link1.Visible = true;
                        //img_1.Visible = true;
                        img1.Visible = true;
                    }
                    else if (i == 2)
                    {
                        //lb_2.Visible = true;
                        lb2.Visible = true;
                        lt2.Visible = true;
                        //img_2.Visible = true;
                        link2.Visible = true;
                        img2.Visible = true;
                    }
                    else if (i == 3)
                    {
                       // lb_3.Visible = true;
                        lb3.Visible = true;
                        lt3.Visible = true;
                        link3.Visible = true;
                        //img_3.Visible = true;
                        img3.Visible = true;
                    }
                 
                }

                int count = 1;
                foreach (var item in featured)
                {
                    if (count == 1)
                    {
                        post1.Text = item.postidPK.ToString();
                        lb1.Text = item.posttitle.ToUpper();
                        lt_1.Text = HtmlRemoval.StripTagsCharArray(truncate(item.postdescription.ToString()));
                        img1.ImageUrl = "../FilStartUps_Images.ashx?id=" + item.postidPK;
                        
                    }
                    else if (count == 2)
                    {
                        post2.Text = item.postidPK.ToString();
                       // lb_2.Text = item.posttitle;
                        lb2.Text = item.posttitle.ToUpper();
                        lt2.Text = HtmlRemoval.StripTagsCharArray(truncate(item.postdescription.ToString()));
                        //img_2.ImageUrl = "../FilStartUps_Images.ashx?id=" + item.postidPK;
                        img2.ImageUrl = "../FilStartUps_Images.ashx?id=" + item.postidPK;
                    }
                    else if (count == 3)
                    {
                        post3.Text = item.postidPK.ToString();
                        lb3.Text = item.posttitle.ToUpper();
                        lt3.Text = HtmlRemoval.StripTagsCharArray(truncate(item.postdescription.ToString()));
                        //img_3.ImageUrl = "../FilStartUps_Images.ashx?id=" + item.postidPK;
                        img3.ImageUrl = "../FilStartUps_Images.ashx?id=" + item.postidPK;
                    }
               
                    count++;

                }
            }
            catch
            {

            }

            //lbfeaturedposttitle.Text = featured.posttitle;
            //lbpostidfeatured.Text = featured.postidPK.ToString();
            //ltfeaturedpostdesc.Text = truncate(featured.postdescription).ToString();
            //imgPost.ImageUrl = "../FilStartUps_Images.ashx?id=" + featured.postidPK;
        }

        private string truncate(string desc)
        {
            string description;

            try
            {
                description = desc.ToString().Substring(0, 200);
            }
            catch
            {
                description = desc;
            }
            return description;

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetFeatured();
            }
        }

        protected void link1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Article.aspx?p=" + post1.Text);
        }

        protected void link2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Article.aspx?p=" + post2.Text);
        }

        protected void link3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Article.aspx?p=" + post3.Text);
        }
        protected void btnfeaturedrss_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/rss.aspx?ID=4");
        }
    }
}